package com.woniuxy.credit_loans.audit_li.service.impl;

import com.woniuxy.credit_loans.audit_li.dto.AuditInfoDto;
import com.woniuxy.credit_loans.audit_li.service.AuditInfoService;
import com.woniuxy.credit_loans.entity.AuditInfo;
import com.woniuxy.credit_loans.mapper.AuditInfoMapper;
import com.woniuxy.credit_loans.util.TimeUtilLi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author ：halisir
 * @date ：Created in 2022/12/13 19:57
 * @description：
 * @modified By：
 * @version: $
 */
@Service
public class AuditInfoServiceImpl implements AuditInfoService {
    @Autowired
    private AuditInfoMapper auditInfoMapper;
    @Override
    public AuditInfoDto selectByDiNumber(Integer diNumber) {
        return auditInfoMapper.selectByDiNumber(diNumber);
    }

    @Override
    public int insertSelectiveByDiNumber(AuditInfoDto record) {
        AuditInfoDto auditInfoDto = auditInfoMapper.selectByDiNumber(record.getDiNumber());
        if (auditInfoDto != null) {
            String s1 = TimeUtilLi.DateToString(new Date());
            record.setAiAssessor("审核经理熊熊");
            switch (record.getAiResult()){
                case "1": record.setAiResult("通过");
                break;
                case "2": record.setAiResult("驳回");
                break;
                case "3": record.setAiResult("拒绝");
                break;
            }
            record.setAiBy1(s1);
            if (record.getAiResult().equals("驳回")){
                record.setAiStage("终审驳回");
            }else if(record.getAiResult().equals("拒绝")){
                record.setAiStage("拒绝申请");
            }
            record.setAiStage("终审");
            int i = auditInfoMapper.insertSelectiveByDiNumber(record);

            return i;

        }else {
            String s = TimeUtilLi.DateToString(new Date());
            record.setAiAssessor("审核员莉莉");
            switch (record.getAiResult()){
                case "1": record.setAiResult("通过");
                    record.setAiStage("初审");
                    break;
                case "2": record.setAiResult("驳回");
                    record.setAiStage("初审驳回");
                    break;
                case "3": record.setAiResult("拒绝");
                    record.setAiStage("拒绝申请");
                    break;
            }
            record.setAiBy1(s);

            int i = auditInfoMapper.insertSelectiveByDiNumber(record);

            return i;
        }
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return auditInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertSelective(AuditInfo record) {
        return auditInfoMapper.insertSelective(record);
    }

    @Override
    public AuditInfo selectByPrimaryKey(Long id) {
        return auditInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(AuditInfo record) {
        return auditInfoMapper.updateByPrimaryKeySelective(record);
    }
}
